function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

//判断用户是否绑定手机号
function isBindMobile(){
  var mobile = wx.getStorageSync('mobile') || '';
  if(mobile == ''){
    //跳转到绑定页面
    wx.navigateTo({ url: '/pages/login/login' });
  }else{
    return true;
  }
}
//判断用户输入的手机号是否正确
function isMobile(mobile) {
  if (!(/^1[34578]\d{9}$/.test(mobile))) {
    return false;
  } else{
    return true;
  }
}

//js获取url的参数
function getQueryString(url) {
  if(url && url.indexOf('=')>0){
    var param = url.split('=')[1];
    return param;
  }else{
    return false;
  }
} 

//时间戳格式化函数
// function getDateformat(time) {
//   return new Date(parseInt(time) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
// } 

function moneyFormat(money){
  if (money.length > 1) {
    if (money[1].length < 2) {
      value = value.toString() + "0";
    }
    return value;
  }
}

//设备顶部错误信息反馈
function topErrorPrompt(that,index){
  var error_info = ['账户余额不足，请先充值',
                    '手机号格式不正确'
                   ];
  that.setData({item: {display: 'show',error_info: error_info[0]},});
  setTimeout(function () { that.setData({ item: { display: 'hide' } }) }, '4000')
}

module.exports = {
  formatTime: formatTime,
  isBindMobile: isBindMobile,
  isMobile: isMobile,
  getQueryString: getQueryString,
  moneyFormat: moneyFormat,
  topErrorPrompt:topErrorPrompt
}
